#pragma once

#include <iostream>
#include <unistd.h>
#include <pthread.h>
#include <thread>
#include <mutex>

namespace Local_Mutex
{
    struct LocalMutex
    {
        pthread_mutex_t _mutex;
        LocalMutex()
        {
            pthread_mutex_init(&_mutex, NULL);
        }
        ~LocalMutex()
        {
            pthread_mutex_destroy(&_mutex);
        }
        void Lock()
        {
            pthread_mutex_lock(&_mutex);
        }
        void Unlock()
        {
            pthread_mutex_unlock(&_mutex);
        }
    };

    struct LockGuard
    {
        LocalMutex *_lockguard;
        LockGuard(LocalMutex *lockguard)
            : _lockguard(lockguard)
        {
            _lockguard->Lock();
        }
        ~LockGuard()
        {
            _lockguard->Unlock();
        }
    };
}
